<?php

namespace app\adminapi\middleware;

use app\Request;
use app\service\system\admin\AdminAuthServices;
use interfaces\MiddlewareInterface;
use think\facade\Config;

class AdminAuthTokenMiddleware implements MiddlewareInterface
{

    public function handle(Request $request, \Closure $next)
    {
        $token = trim(ltrim($request->header(Config::get('cookie.token_name', 'Authori-zation')), 'Bearer'));
        if (!$token) {
            $token = trim(ltrim($request->get('token')));
        }
        /** @var \app\service\system\admin\AdminAuthServices $service */
        $service = app()->make(AdminAuthServices::class);
        $service->parseToken($token);
    }
}